package com.ruoyi.livesass.api.service;

import java.util.Arrays;
import java.util.List;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.ruoyi.livesass.api.mapper.LbsGkscDayMapper;
import com.ruoyi.livesass.api.domain.LbsGkscDay;
import com.ruoyi.livesass.api.pojo.query.LbsGkscDayQuery;

/**
 * 用户每日观看时长Service业务层处理
 *
 *
 * @author ydb
 */
@Service
public class LbsGkscDayService {
    @Autowired
    private LbsGkscDayMapper lbsGkscDayMapper;

    /**
     * 查询用户每日观看时长
     *
     * @param id 用户每日观看时长主键
     * @return 用户每日观看时长
     */
    public LbsGkscDay selectById(Long id) {
        return lbsGkscDayMapper.selectById(id);
    }

    /**
     * 查询用户每日观看时长列表
     *
     * @param query 查询条件
     * @param page 分页条件
     * @return 用户每日观看时长
     */
    public List<LbsGkscDay> selectList(LbsGkscDayQuery query, Pageable page) {
        if (page != null) {
            PageHelper.startPage(page.getPageNumber() + 1, page.getPageSize());
        }
        QueryWrapper<LbsGkscDay> qw = new QueryWrapper<>();
        qw.eq("del_flag",0);
        Long wcUserId = query.getWcUserId();
        if (wcUserId != null) {
            qw.eq("wc_user_id", wcUserId);
        }
        Long zbjid = query.getZbjid();
        if (zbjid != null) {
            qw.eq("zbjid", zbjid);
        }
        Long spreaduid = query.getSpreaduid();
        if (spreaduid != null) {
            qw.eq("spreaduid", spreaduid);
        }
        

        String subnameLike = query.getSubnameLike();
        if (!StringUtils.isEmpty(subnameLike)) {
            qw.like("subname", subnameLike);
        }
        String nicknameLike = query.getNicknameLike();
        if (!StringUtils.isEmpty(nicknameLike)) {
            qw.like("nickname", nicknameLike);
        }
        String avatar = query.getAvatar();
        if (!StringUtils.isEmpty(avatar)) {
            qw.eq("avatar", avatar);
        }
        String ssquid = query.getSsquid();
        if (!StringUtils.isEmpty(ssquid)) {
            qw.eq("ssquid", ssquid);
        }
        
        
        String beginGsrq = query.getBeginGsrq();
        if (!StringUtils.isEmpty(beginGsrq)) {
            qw.ge("gsrq", beginGsrq);
        }
        
        String endGsrq = query.getEndGsrq();
        if (!StringUtils.isEmpty(endGsrq) ) {
            qw.le("gsrq", endGsrq);
        }
        
        
        
        Integer livetime = query.getLivetime();
        if (livetime != null) {
            qw.ge("livetime", livetime);
        }
        
        Long deptZbjId = query.getDeptZbjId();
        if (deptZbjId != null) {
            qw.eq("dept_zbj_id", deptZbjId);
        }
        Long deptTzId = query.getDeptTzId();
        if (deptTzId != null) {
            qw.eq("dept_tz_id", deptTzId);
        }
        Long deptDpId = query.getDeptDpId();
        if (deptDpId != null) {
            qw.eq("dept_dp_id", deptDpId);
        }
        
        qw.orderByDesc("livetime");
        
        return lbsGkscDayMapper.selectList(qw);
    }

    /**
     * 新增用户每日观看时长
     *
     * @param lbsGkscDay 用户每日观看时长
     * @return 结果
     */
    public int insert(LbsGkscDay lbsGkscDay) {
        lbsGkscDay.setDelFlag("0");
        lbsGkscDay.setCreateTime(LocalDateTime.now());
        return lbsGkscDayMapper.insert(lbsGkscDay);
    }

    /**
     * 修改用户每日观看时长
     *
     * @param lbsGkscDay 用户每日观看时长
     * @return 结果
     */
    public int update(LbsGkscDay lbsGkscDay) {
        return lbsGkscDayMapper.updateById(lbsGkscDay);
    }

    /**
     * 批量删除用户每日观看时长
     *
     * @param ids 需要删除的用户每日观看时长主键
     * @return 结果
     */
    public int deleteByIds(Long[] ids) {
        return lbsGkscDayMapper.updateDelFlagByIds(ids);
    }

    /**
     * 删除用户每日观看时长信息
     *
     * @param id 用户每日观看时长主键
     * @return 结果
     */
    public int deleteById(Long id) {
        Long[] ids = {id};
        return lbsGkscDayMapper.updateDelFlagByIds(ids);
    }
}
